/***********************************************************************************
 * 文件名： LHS096TV-IG92.c
 * 作者： 黄均铭
 * 版本： 1
 * 说明：
 *      LHS096TV-IG92 初始化函数
 * 修改记录：
 * 	2024/01/09: 初版。 黄均铭。
 ***********************************************************************************/
#include "lcd_config.h"
#include "polsys.h"
#include "st7735sv.h"


#define LCD_DIR      0  // 显示方向 0：垂直（ROW） 1：水平（COL）
#define LCD_ORIGIN   3  // 原点位置 0：靠近1脚 1：靠近13脚 2：1对角线 3：0对角线


// 函数名称固定，给 Lcd_Init 调用
// 初始化函数可能依据不同的屏幕其内容要做修改，建议参考屏幕厂商例程
void Lcd_ChipInit()
{
    _Lcd_PortInit();

    // 硬件复位
    _Lcd_SetRstLevel(0);
    _Lcd_Delayms(1);
    _Lcd_SetRstLevel(1);
    // _Lcd_Delayms(120);
    _Lcd_Delayms(1);

    // 软复位
    WriteOneByteCmd(_CMD_SOFT_RESET);
    _Lcd_Delayms(1);
    WriteOneByteCmd(_CMD_SLEEP_OUT);
    _Lcd_Delayms(1);

    //------------------------------------ST7735S Frame Rate-----------------------------------------//
    WriteOneByteCmd(0xB1);
    WriteOneByteData(0x05); // 0x05
    WriteOneByteData(0x3A); // 0x3A
    WriteOneByteData(0x3A); // 0x3A
    WriteOneByteCmd(0xB2);
    WriteOneByteData(0x05);
    WriteOneByteData(0x3A);
    WriteOneByteData(0x3A);
    WriteOneByteCmd(0xB3);
    WriteOneByteData(0x05);
    WriteOneByteData(0x3A);
    WriteOneByteData(0x3A);
    WriteOneByteData(0x05);
    WriteOneByteData(0x3A);
    WriteOneByteData(0x3A);
    //------------------------------------End ST7735S Frame Rate-----------------------------------------//
    WriteOneByteCmd(0xB4); // Dot inversion
    WriteOneByteData(0x03);
    //------------------------------------ST7735S Power Sequence-----------------------------------------//
    WriteOneByteCmd(0xC0);
    WriteOneByteData(0x62);
    WriteOneByteData(0x02);
    WriteOneByteData(0x04);
    WriteOneByteCmd(0xC1);
    WriteOneByteData(0xC0);
    WriteOneByteCmd(0xC2);
    WriteOneByteData(0x0D);
    WriteOneByteData(0x00);
    WriteOneByteCmd(0xC3);
    WriteOneByteData(0x8D);
    WriteOneByteData(0x6A);
    WriteOneByteCmd(0xC4);
    WriteOneByteData(0x8D);
    WriteOneByteData(0xEE);
    //---------------------------------End ST7735S Power Sequence-------------------------------------//
    WriteOneByteCmd(0xC5);  // VCOM
    WriteOneByteData(0x12); // 0x12
    //------------------------------------ST7735S Gamma Sequence-----------------------------------------//
    WriteOneByteCmd(0xE0);
    WriteOneByteData(0x03);
    WriteOneByteData(0x1B);
    WriteOneByteData(0x12);
    WriteOneByteData(0x11);
    WriteOneByteData(0x3F);
    WriteOneByteData(0x3A);
    WriteOneByteData(0x32);
    WriteOneByteData(0x34);
    WriteOneByteData(0x2F);
    WriteOneByteData(0x2B);
    WriteOneByteData(0x30);
    WriteOneByteData(0x3A);
    WriteOneByteData(0x00);
    WriteOneByteData(0x01);
    WriteOneByteData(0x02);
    WriteOneByteData(0x05);
    WriteOneByteCmd(0xE1);
    WriteOneByteData(0x03);
    WriteOneByteData(0x1B);
    WriteOneByteData(0x12);
    WriteOneByteData(0x11);
    WriteOneByteData(0x32);
    WriteOneByteData(0x2F);
    WriteOneByteData(0x2A);
    WriteOneByteData(0x2F);
    WriteOneByteData(0x2E);
    WriteOneByteData(0x2C);
    WriteOneByteData(0x35);
    WriteOneByteData(0x3F);
    WriteOneByteData(0x00);
    WriteOneByteData(0x00);
    WriteOneByteData(0x01);
    WriteOneByteData(0x05);
    //------------------------------------End ST7735S Gamma Sequence-----------------------------------------//
    WriteOneByteCmd(0x21); // 显示倒置，颜色反向显示
    // WriteOneByteCmd(0xFC); //Enable Gate power save mode
    WriteOneByteData(0x8C);
    WriteOneByteCmd(0x3A); // 65k mode
    WriteOneByteData(0x05);
    WriteOneByteCmd(0x36);                                       // 数据写入顺序
    WriteOneByteData(0x08 | (LCD_ORIGIN << 6) | (LCD_DIR << 5)); // bit7:行顺序 bit6:列顺序 bit5:行列交换 bit4:垂直刷新方向 bit3:RGB/BGR bit2:水平刷新方向
    //------------------------------------部分模式 只显示部分区域-----------------------------------------//
#if LCD_DIR == 0
    WriteOneByteCmd(0x30); // 部分模式区域
    WriteOneByteData(0);
    WriteOneByteData(LCD_OFFSET_Y); // 开始行
    WriteOneByteData(0);
    WriteOneByteData(LCD_OFFSET_Y + LCD_SIZE_Y); // 结束行
    WriteOneByteCmd(0x12);                       // 部分模式开启
#else
    WriteOneByteCmd(0x30); // 部分模式区域
    WriteOneByteData(0);
    WriteOneByteData(LCD_OFFSET_X); // 开始行
    WriteOneByteData(0);
    WriteOneByteData(LCD_OFFSET_X + LCD_SIZE_X); // 结束行
    WriteOneByteCmd(0x12);                       // 部分模式开启
#endif
    // WriteOneByteCmd(0x13); // 部分模式关闭
    // 0x37 垂直滚动地址 0x33滚动模式

    // // 开启显示
    // WriteOneByteCmd(0x29);
}




